1
/************************************* Module Header **************************************\
2 * Module Name: Converters.cs
3 * Project: CSWPFDataBinding
4 * Copyright (c) Microsoft Corporation.
6 * This example demonstrates how to use DataBinding in WPF
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
14 * * 10/29/2009 3:00 PM Bruce Zhou Created
16 \******************************************************************************************/
18 using System
.Collections
.Generic
;
21 using System
.Windows
.Data
;
23 namespace CSWPFDataBinding
25 public class SalaryFormmatingConverter
:IValueConverter
28 #region IValueConverter Members
30 public object Convert(object value, Type targetType
, object parameter
, System
.Globalization
.CultureInfo culture
)
33 string formattedSalary
= string.Empty
;
37 throw new NullReferenceException("value can not be null");
41 Double
.TryParse(value.ToString(), out dolloars
);
43 formattedSalary
= String
.Format("Total={0}$", dolloars
);
44 return formattedSalary
;
47 public object ConvertBack(object value, Type targetType
, object parameter
, System
.Globalization
.CultureInfo culture
)
52 throw new NullReferenceException("value can not be null");
55 Double
.TryParse(value.ToString().TrimStart(new Char
[] {'T', 't', 'o', 'a', 'l', '='}
).TrimEnd('$'), out dolloars
);